<template>
  <view class="app-container">
    <div class="title-container">
      <div>
        <image src="/static/icons/jibie.svg" mode=""></image>
        <text class="title">我的级别</text>
      </div>
      <div>
        <text class="name">{{ levelName }}</text>
        <navigator style="display: inline-block" url="/pages/inviteuser/inviteuser">
          <image src="/static/icons/fenxiang.svg" mode=""></image>
        </navigator>
      </div>
    </div>
    <div class="device-num">
      <div class="item">
        <div>{{ totalPhoneCount }}</div>
        <div>团队总设备</div>
      </div>
      <div class="item">
        <div>{{ expirePhoneCount }}</div>
        <div>有效设备</div>
      </div>
      <div class="item">
        <div>{{ effectPhoneCount }}</div>
        <div>失效设备</div>
      </div>
    </div>
    <div class="teamdetail-container">
      <div class="title">团队详情</div>
      <u-input prefixIcon="search" shape="circle" prefixIconStyle="font-size: 22px;color: #909399" v-model="searchVal"
        placeholder="请输入需要管理手机号或昵称" class="search-input"></u-input>
      <div class="list">
        <div class="item" v-for="(item, i) in dataList" :key="i">
          <div class="top" :class="isInvalid ? 'invalid' : ''">
            <text @click="onClick(item, i)">{{ item.text }}</text>
          </div>
          <div class="content">
            <div class="content-1">
              <div class="biaoti">
                <text>编号</text>
                <text>昵称</text>
                <text>备注</text>
                <text>手机号</text>
                <text>级别</text>
              </div>
              <div class="value">
                <text>{{ item.id }}</text>
                <text>{{ item.nickName }}</text>
                <text> </text>
                <text>{{ item.phone }}</text>
                <text>{{ levelName }}</text>
              </div>
            </div>
            <div class="content-2" v-if="item.show">
              <u-cell-group :border="false">
                <u-cell :border="false" title="自由设备数" :value="item.totalPhoneCount">
                  <text slot="value">{{ item.totalPhoneCount }}</text>
                </u-cell>
                <u-cell :border="false" title="有效" isLink :url="`/pages/validdevice/validdevice?id=92`"
                  :value="item.effectPhoneCount">
                  <text slot="value">{{ item.effectPhoneCount }}</text>
                </u-cell>
                <u-cell :border="false" title="失效" isLink url="/pages/invaliddevice/invaliddevice?id=98"
                  :value="item.expirePhoneCount">

                  <text slot="value">{{ item.expirePhoneCount }}</text></u-cell>
              </u-cell-group>
            </div>
          </div>
        </div>
      </div>
    </div>
    <modal-popup></modal-popup>
  </view>
</template>

<script>
import { effectPhone, promoteList } from '@/api/api.js'
import ModalPopup from '@/components/ModalPopup/ModalPopup.vue'
export default {
  components: { ModalPopup },
  data() {
    return {
      searchVal: '',
      isInvalid: false,
      index: 1,
      btnText: '展开',
      dataList: [
        { show: false, text: '展开' },
        { show: false, text: '展开' }
      ],
      totalPhoneCount: '',//总数
      effectPhoneCount: '',//失效
      expirePhoneCount: ''//有效
    }
  },
  nHide() {
    this.$store.dispatch('changeShowAction', false)
  },
  mounted() {
    this.init()
  },
  computed: {
    levelName() {
      return this.$store.state.user.levelName
    }
  },
  methods: {
    init() {
      effectPhone().then(res => {
      })
      promoteList({ id: this.$store.state.user.id }).then(res => {
        if (res.code === 10000) {
          this.totalPhoneCount = res.data.totalPhoneCount
          this.effectPhoneCount = res.data.effectPhoneCount
          this.expirePhoneCount = res.data.expirePhoneCount
          this.dataList = res.data.users.map(e => ({
            ...e,
            show: false,
            text: '展开',
          }))
        }
      })
    },
    onClick(item, i) {
      this.$set(this.dataList, i, {...item, show: !item.show, text: !item.show ? '收起' : '展开' })
    }
  }
}
</script>

<style lang="scss">
.title-container {
  display: flex;
  justify-content: space-between;
  flex-wrap: nowrap;
  background-color: #fff;
  padding: 15px 12px;
  margin-bottom: 16px;

  .title {
    color: #00b6fc;
    margin-left: 10px;
  }

  .name {
    margin-right: 10px;
  }

  image {
    width: 16px;
    height: 16px;
    vertical-align: middle;
  }

  text {
    vertical-align: middle;
  }
}

.device-num {
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;

  .item {
    width: 100px;
    height: 80px;
    background-color: #fff;
    border-radius: 4px;
    margin-right: 12px;
    padding: 14px;
    text-align: center;
    box-sizing: border-box;

    div:first-child {
      font-size: 24px;
      font-weight: bold;
    }

    div:last-child {
      font-size: 14px;
    }

    &:last-child {
      margin-right: 0;
    }
  }
}

.teamdetail-container {
  padding: 12px;
  background-color: #fff;

  .title {
    font-size: 18px;
    line-height: 22px;
    margin-bottom: 12px;
  }

  .u-input {
    background-color: #f5f6f7;
    margin-bottom: 14px;

    &::deep::placeholder {
      color: #c7c7c7;
    }
  }

  .list {
    .item {
      border-radius: 10px;
      border: 1px solid #f5f6f7;
      overflow: hidden;
      margin-bottom: 12px;

      .top {
        padding: 4px 12px;
        background-color: #f5f6f7;
        background-repeat: no-repeat;
        text-align: right;
        font-size: 12px;
        color: #00b6fc;

        &.invalid {
          background-image: url('@/static/icons/shixiao.svg');
        }
      }

      .content {
        .content-1 {
          padding: 12px 12px 0;

          .biaoti,
          .value {
            display: flex;
            justify-content: space-between;
            flex-wrap: nowrap;
            margin-bottom: 10px;

            text {
              display: block;
              font-size: 12px;
              line-height: 18px;

              &:nth-of-type(1) {
                width: 30px;
              }

              &:nth-of-type(2) {
                width: 50px;
              }

              &:nth-of-type(3) {
                width: 50px;
              }

              &:nth-of-type(4) {
                width: 90px;
              }

              &:nth-of-type(5) {
                width: 50px;
              }
            }

            &.value {
              padding-bottom: 10px;
              margin-bottom: 0;
              border-bottom: 1px solid #d8d8d8;
            }
          }
        }

        .content-2 {
          height: 132px;
          transition: all 0.3s;
        }
      }
    }
  }
}
</style>
